load("//bazel:mongo_src_rules.bzl", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "op_observer",
    srcs = [
        "op_observer.cpp",
        "op_observer_registry.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db/storage:container",
        "//src/mongo/db/storage/key_string",
    ],
)

mongo_cc_library(
    name = "op_observer_util",
    srcs = [
        "op_observer_util.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/bson/dotted_path:dotted_path_support",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/rss:replicated_storage_service",
        "//src/mongo/db/shard_role/shard_catalog:collection_options",
    ],
)

mongo_cc_library(
    name = "operation_logger_transaction_proxy",
    srcs = [
        "operation_logger_transaction_proxy.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

mongo_cc_library(name = "operation_logger_mock")

mongo_cc_library(
    name = "user_write_block_mode_op_observer",
    srcs = [
        "//src/mongo/db/topology/user_write_block:user_write_block_mode_op_observer.cpp",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/topology/user_write_block:user_writes_recoverable_critical_section",
    ],
)

mongo_cc_library(
    name = "find_and_modify_images_op_observer",
    srcs = [
        "find_and_modify_images_op_observer.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:commands",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/db/shard_role/shard_catalog:document_validation",
    ],
)

mongo_cc_library(
    name = "change_stream_pre_images_op_observer",
    srcs = [
        "change_stream_pre_images_op_observer.cpp",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:change_stream_pre_images_collection_manager",
        "//src/mongo/db:server_base",
        "//src/mongo/db/pipeline:change_stream_preimage",
        "//src/mongo/db/repl:optime",
        "//src/mongo/db/transaction:transaction_operations",
    ],
)

mongo_cc_library(
    name = "fallback_op_observer",
    srcs = [
        "fallback_op_observer.cpp",
    ],
    deps = [
        ":batched_write_context",
        ":op_observer",
        ":op_observer_util",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db:vector_clock",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/shard_role/shard_catalog:collection_catalog",
        "//src/mongo/db/transaction",
        "//src/mongo/db/views:view_catalog_helpers",
    ],
)

mongo_cc_library(
    name = "op_observer_impl",
    srcs = [
        "op_observer_impl.cpp",
    ],
    deps = [
        ":batched_write_context",
        ":op_observer",
        ":op_observer_util",
        "//src/mongo/db:import_collection_oplog_entry",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db/commands:txn_cmd_request",
        "//src/mongo/db/index_builds:commit_quorum_options",
        "//src/mongo/db/repl:repl_server_parameters",
        "//src/mongo/db/repl:truncate_range_oplog_entry_idl",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/shard_role/shard_catalog:catalog_helpers",
        "//src/mongo/db/shard_role/shard_catalog:collection_catalog",
        "//src/mongo/db/shard_role/shard_catalog:collection_options",
        "//src/mongo/db/shard_role/shard_catalog:database_holder",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_operations",
        "//src/mongo/s:grid",
    ],
)

mongo_cc_library(
    name = "batched_write_context",
    srcs = [
        "batched_write_context.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/transaction:transaction_operations",
    ],
)

mongo_cc_library(
    name = "operation_logger_impl",
    srcs = [
        "operation_logger_impl.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db/repl:oplog",
    ],
)

mongo_cc_library(
    name = "fcv_op_observer",
    srcs = [
        "fcv_op_observer.cpp",
    ],
    deps = [
        ":op_observer",
        ":op_observer_util",
        "//src/mongo:base",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/session:kill_sessions_local",
        "//src/mongo/executor:egress_connection_closer_manager",
    ],
)

mongo_cc_unit_test(
    name = "db_op_observer_test",
    srcs = [
        "op_observer_impl_test.cpp",
        "//src/mongo/db/topology/user_write_block:user_write_block_mode_op_observer_test.cpp",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        ":batched_write_context",
        ":change_stream_pre_images_op_observer",
        ":find_and_modify_images_op_observer",
        ":op_observer",
        ":op_observer_impl",
        ":op_observer_util",
        ":operation_logger_impl",
        ":user_write_block_mode_op_observer",
        "//src/mongo/db:change_stream_pre_images_collection_manager",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:import_collection_oplog_entry",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:read_write_concern_defaults_mock",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/repl:local_oplog_info",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:oplog_interface_local",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/shard_role/shard_catalog:catalog_helpers",
        "//src/mongo/db/storage:recovery_unit_base",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/topology/user_write_block:write_block_bypass",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_operations",
    ],
)

mongo_cc_unit_test(
    name = "db_batched_write_test",
    srcs = [
        "batched_write_context_test.cpp",
        "batched_write_policy_test.cpp",
    ],
    tags = [
        "mongo_unittest_seventh_group",
        "server-storage-engine-integration",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:service_context_d_test_fixture",
    ],
)

mongo_cc_unit_test(
    name = "op_observer_registry_test",
    srcs = [
        "op_observer_registry_test.cpp",
    ],
    tags = [
        "mongo_unittest_third_group",
        "server-storage-engine-integration",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:service_context_d_test_fixture",
    ],
)

mongo_cc_benchmark(
    name = "op_observer_bm",
    srcs = [
        "op_observer_bm.cpp",
    ],
    deps = [
        ":change_stream_pre_images_op_observer",
        ":fallback_op_observer",
        ":fcv_op_observer",
        ":find_and_modify_images_op_observer",
        ":op_observer",
        ":op_observer_impl",
        ":op_observer_util",
        ":operation_logger_impl",
        ":operation_logger_transaction_proxy",
        ":user_write_block_mode_op_observer",
        "//src/mongo/db:service_context_d",
        "//src/mongo/db/auth:auth_op_observer",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db/repl:primary_only_service",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/s:sharding_runtime_d",
        "//src/mongo/db/shard_role/shard_catalog:collection_mock",
        "//src/mongo/db/timeseries:timeseries_op_observer",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_op_observer",
    ],
)
